package main

import (
	"archive/zip"
	"io"
	"os"
	"path/filepath"
)

// 解压zip文件到指定目录 zipfilename:zip文件名 distDir：解压目录
func DecompressZipTo(zipfilename string, distDir string) {
	zipfile, _ := zip.OpenReader(zipfilename)
	defer zipfile.Close()
	for _, f := range zipfile.File {
		zipFilePath := filepath.Join(distDir, f.Name)
		if f.FileInfo().IsDir() {
			_ = os.MkdirAll(zipFilePath, f.Mode())
			continue
		}
		os.MkdirAll(filepath.Dir(zipFilePath), f.Mode())
		dstFile, _ := os.OpenFile(zipFilePath, os.O_WRONLY|os.O_CREATE, f.Mode())
		file, _ := f.Open()
		io.Copy(dstFile, file)
		dstFile.Close()
		file.Close()
	}
}
